home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / c-tools-.000 / c-tools- / c-tools-0.4 / examples / stripcr.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-13  |  895 b   |  45 lines

  1. /* stripcr.c -- remove carriage returns from input file */
  2.  
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. #include <ctype.h>
  7. #include <assert.h>
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.     FILE *fin = stdin, *fout = stdout;
  12.     int c;
  13.  
  14.     if (argc > 1) {
  15.     if (!strcmp(argv[1], "-h") || argc > 3) {
  16.         fprintf(stderr, "\
  17. %s: remove carriage returns from input file\n\
  18. usage: %s [input] [[output]]\n", argv[0], argv[0]);
  19.         exit(0);
  20.     } else {
  21.         if (strcmp(argv[1], "-") != 0 &&
  22.         (fin = fopen(argv[1], "rb")) == NULL) {
  23.         fprintf(stderr, "%s: no such file\n", argv[1]);
  24.         exit(1);
  25.         }
  26.     }
  27.     if (argc == 3) {
  28.         if ((fout = fopen(argv[2], "wb")) == NULL) {
  29.         fprintf(stderr, "%s: cannot open output file\n", argv[2]);
  30.         exit(1);
  31.         }
  32.     }
  33.     }
  34.     while ((c = fgetc(fin)) != EOF)
  35.     if (c != 0x0d)
  36.         fputc(c, fout);
  37.  
  38.     fclose(fin);
  39.     fclose(fout);
  40.  
  41.     return 0;
  42. }
  43.  
  44. /* stripcr.c ends here */
  45.